package books.ThinkingInJava.src.Chapter18;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author bloodcolding
 * @since 12/28/2018 5:22 PM
 */
public class OsExcute {
    public static void main(String[] args) throws IOException {
        new OsExcute().excute("ls");
    }

    public void excute(String command) throws IOException {
        Process process = new ProcessBuilder(command.split(" ")).start();
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String s = null;
        while ((s = in.readLine()) != null) {
            System.out.println(s);
        }
        BufferedReader err = new BufferedReader(new InputStreamReader((process.getErrorStream())));
        while ((s = err.readLine()) != null) {
            System.out.println(s);
        }
        in.close();
        err.close();

    }

}

